#ifndef __X_GUID_H__
#define __X_GUID_H__

class CGuidCollector
{
public:
	CGuidCollector();
	~CGuidCollector();
	U32 GenID();
	void FreeID(U32 n_id);
protected:
	U32						m_nCurId;
	U32						m_nMaxId;
	std::vector<U32>		m_IDList;
};

class CGuidMgr
{
	SINGLETON_CLASS(CGuidMgr)
public:
	enum _eEntityType
	{
		ENTITY_NONE = -1,
		ENTITY_ROLE = 0,
		ENTITY_USER,
		ENTITY_LOGIN_USER,
		ENTITY_SERVER,
		ENTITY_LINKS,
		ENTITY_LINK_CLIENT,
		ENTITY_LINK_SRV,
		ENTITY_ROOM,
		ENTITY_STATIC_ROOM,
		ENTITY_DYNAMIC_ROOM,
		ENTITY_NPC,
		ENTITY_FLASH_NPC_COMM,
		ENTITY_SOLDIER,
		ENTITY_TOLLGATE,

		ENTITY_END
	};
	struct _X_GUID
	{
		union
		{
			struct{
				U32		SrvID:12;
				U32		SrvType:4;
				U32		SrvIndex:4;
				U32		nReslove:4;
				U32		EntityType:8;
				U32		uID;
			};
			U64			xGuid;
		};
		_X_GUID() {xGuid = 0;}
		_X_GUID(U64 u) {xGuid = u;}
		operator U64()
		{
			return xGuid;
		}
	};
	CGuidMgr();
	~CGuidMgr();

	_X_GUID GenGUID(U32 EntityType, U32 parameter = 0);
	_X_GUID GenHighGUID(U32 EntityType);

protected:
	U32 GenHashUUID();
	U32 GenID() {return m_idCollector.GenID();}
	void FreeID(U64 uGuid);
private:
	CGuidCollector		m_idCollector;
};
#endif//__X_GUID_H__